Left Termination of the query pattern flat_in_2(g, a) w.r.t. the given Prolog program could successfully be proven:



Prolog
  ↳ PrologToPiTRSProof

Clauses:

right(tree(X, XS1, XS2), XS2).
flat(niltree, nil).
flat(tree(X, niltree, XS), cons(X, YS)) :- ','(right(tree(X, niltree, XS), ZS), flat(ZS, YS)).
flat(tree(X, tree(Y, YS1, YS2), XS), ZS) :- flat(tree(Y, YS1, tree(X, YS2, XS)), ZS).

Queries:

flat(g,a).

We use the technique of [30].Transforming Prolog into the following Term Rewriting System:
Pi-finite rewrite system:
The TRS R consists of the following rules:

flat_in(tree(X, tree(Y, YS1, YS2), XS), ZS) → U3(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
flat_in(tree(X, niltree, XS), cons(X, YS)) → U1(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)
U1(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U2(X, XS, YS, flat_in(ZS, YS))
flat_in(niltree, nil) → flat_out(niltree, nil)
U2(X, XS, YS, flat_out(ZS, YS)) → flat_out(tree(X, niltree, XS), cons(X, YS))
U3(X, Y, YS1, YS2, XS, ZS, flat_out(tree(Y, YS1, tree(X, YS2, XS)), ZS)) → flat_out(tree(X, tree(Y, YS1, YS2), XS), ZS)

The argument filtering Pi contains the following mapping:
flat_in(x1, x2)  =  flat_in(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U3(x1, x2, x3, x4, x5, x6, x7)  =  U3(x7)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
U1(x1, x2, x3, x4)  =  U1(x1, x4)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U2(x1, x2, x3, x4)  =  U2(x1, x4)
nil  =  nil
flat_out(x1, x2)  =  flat_out(x2)

Infinitary Constructor Rewriting Termination of PiTRS implies Termination of Prolog



↳ Prolog
  ↳ PrologToPiTRSProof
PiTRS
      ↳ DependencyPairsProof

Pi-finite rewrite system:
The TRS R consists of the following rules:

flat_in(tree(X, tree(Y, YS1, YS2), XS), ZS) → U3(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
flat_in(tree(X, niltree, XS), cons(X, YS)) → U1(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)
U1(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U2(X, XS, YS, flat_in(ZS, YS))
flat_in(niltree, nil) → flat_out(niltree, nil)
U2(X, XS, YS, flat_out(ZS, YS)) → flat_out(tree(X, niltree, XS), cons(X, YS))
U3(X, Y, YS1, YS2, XS, ZS, flat_out(tree(Y, YS1, tree(X, YS2, XS)), ZS)) → flat_out(tree(X, tree(Y, YS1, YS2), XS), ZS)

The argument filtering Pi contains the following mapping:
flat_in(x1, x2)  =  flat_in(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U3(x1, x2, x3, x4, x5, x6, x7)  =  U3(x7)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
U1(x1, x2, x3, x4)  =  U1(x1, x4)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U2(x1, x2, x3, x4)  =  U2(x1, x4)
nil  =  nil
flat_out(x1, x2)  =  flat_out(x2)


Using Dependency Pairs [1,30] we result in the following initial DP problem:
Pi DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → U31(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)), ZS)
FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → U11(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → RIGHT_IN(tree(X, niltree, XS), ZS)
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U21(X, XS, YS, flat_in(ZS, YS))
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → FLAT_IN(ZS, YS)

The TRS R consists of the following rules:

flat_in(tree(X, tree(Y, YS1, YS2), XS), ZS) → U3(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
flat_in(tree(X, niltree, XS), cons(X, YS)) → U1(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)
U1(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U2(X, XS, YS, flat_in(ZS, YS))
flat_in(niltree, nil) → flat_out(niltree, nil)
U2(X, XS, YS, flat_out(ZS, YS)) → flat_out(tree(X, niltree, XS), cons(X, YS))
U3(X, Y, YS1, YS2, XS, ZS, flat_out(tree(Y, YS1, tree(X, YS2, XS)), ZS)) → flat_out(tree(X, tree(Y, YS1, YS2), XS), ZS)

The argument filtering Pi contains the following mapping:
flat_in(x1, x2)  =  flat_in(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U3(x1, x2, x3, x4, x5, x6, x7)  =  U3(x7)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
U1(x1, x2, x3, x4)  =  U1(x1, x4)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U2(x1, x2, x3, x4)  =  U2(x1, x4)
nil  =  nil
flat_out(x1, x2)  =  flat_out(x2)
RIGHT_IN(x1, x2)  =  RIGHT_IN(x1)
U31(x1, x2, x3, x4, x5, x6, x7)  =  U31(x7)
U21(x1, x2, x3, x4)  =  U21(x1, x4)
U11(x1, x2, x3, x4)  =  U11(x1, x4)
FLAT_IN(x1, x2)  =  FLAT_IN(x1)

We have to consider all (P,R,Pi)-chains

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
PiDP
          ↳ DependencyGraphProof

Pi DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → U31(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)), ZS)
FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → U11(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → RIGHT_IN(tree(X, niltree, XS), ZS)
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U21(X, XS, YS, flat_in(ZS, YS))
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → FLAT_IN(ZS, YS)

The TRS R consists of the following rules:

flat_in(tree(X, tree(Y, YS1, YS2), XS), ZS) → U3(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
flat_in(tree(X, niltree, XS), cons(X, YS)) → U1(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)
U1(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U2(X, XS, YS, flat_in(ZS, YS))
flat_in(niltree, nil) → flat_out(niltree, nil)
U2(X, XS, YS, flat_out(ZS, YS)) → flat_out(tree(X, niltree, XS), cons(X, YS))
U3(X, Y, YS1, YS2, XS, ZS, flat_out(tree(Y, YS1, tree(X, YS2, XS)), ZS)) → flat_out(tree(X, tree(Y, YS1, YS2), XS), ZS)

The argument filtering Pi contains the following mapping:
flat_in(x1, x2)  =  flat_in(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U3(x1, x2, x3, x4, x5, x6, x7)  =  U3(x7)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
U1(x1, x2, x3, x4)  =  U1(x1, x4)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U2(x1, x2, x3, x4)  =  U2(x1, x4)
nil  =  nil
flat_out(x1, x2)  =  flat_out(x2)
RIGHT_IN(x1, x2)  =  RIGHT_IN(x1)
U31(x1, x2, x3, x4, x5, x6, x7)  =  U31(x7)
U21(x1, x2, x3, x4)  =  U21(x1, x4)
U11(x1, x2, x3, x4)  =  U11(x1, x4)
FLAT_IN(x1, x2)  =  FLAT_IN(x1)

We have to consider all (P,R,Pi)-chains
The approximation of the Dependency Graph [30] contains 1 SCC with 3 less nodes.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
PiDP
              ↳ UsableRulesProof

Pi DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → U11(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)), ZS)
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → FLAT_IN(ZS, YS)

The TRS R consists of the following rules:

flat_in(tree(X, tree(Y, YS1, YS2), XS), ZS) → U3(X, Y, YS1, YS2, XS, ZS, flat_in(tree(Y, YS1, tree(X, YS2, XS)), ZS))
flat_in(tree(X, niltree, XS), cons(X, YS)) → U1(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)
U1(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → U2(X, XS, YS, flat_in(ZS, YS))
flat_in(niltree, nil) → flat_out(niltree, nil)
U2(X, XS, YS, flat_out(ZS, YS)) → flat_out(tree(X, niltree, XS), cons(X, YS))
U3(X, Y, YS1, YS2, XS, ZS, flat_out(tree(Y, YS1, tree(X, YS2, XS)), ZS)) → flat_out(tree(X, tree(Y, YS1, YS2), XS), ZS)

The argument filtering Pi contains the following mapping:
flat_in(x1, x2)  =  flat_in(x1)
tree(x1, x2, x3)  =  tree(x1, x2, x3)
U3(x1, x2, x3, x4, x5, x6, x7)  =  U3(x7)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
U1(x1, x2, x3, x4)  =  U1(x1, x4)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U2(x1, x2, x3, x4)  =  U2(x1, x4)
nil  =  nil
flat_out(x1, x2)  =  flat_out(x2)
U11(x1, x2, x3, x4)  =  U11(x1, x4)
FLAT_IN(x1, x2)  =  FLAT_IN(x1)

We have to consider all (P,R,Pi)-chains
For (infinitary) constructor rewriting [30] we can delete all non-usable rules from R.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
PiDP
                  ↳ PiDPToQDPProof

Pi DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, niltree, XS), cons(X, YS)) → U11(X, XS, YS, right_in(tree(X, niltree, XS), ZS))
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS), ZS) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)), ZS)
U11(X, XS, YS, right_out(tree(X, niltree, XS), ZS)) → FLAT_IN(ZS, YS)

The TRS R consists of the following rules:

right_in(tree(X, XS1, XS2), XS2) → right_out(tree(X, XS1, XS2), XS2)

The argument filtering Pi contains the following mapping:
tree(x1, x2, x3)  =  tree(x1, x2, x3)
niltree  =  niltree
cons(x1, x2)  =  cons(x1, x2)
right_in(x1, x2)  =  right_in(x1)
right_out(x1, x2)  =  right_out(x2)
U11(x1, x2, x3, x4)  =  U11(x1, x4)
FLAT_IN(x1, x2)  =  FLAT_IN(x1)

We have to consider all (P,R,Pi)-chains
Transforming (infinitary) constructor rewriting Pi-DP problem [30] into ordinary QDP problem [15] by application of Pi.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
QDP
                      ↳ Rewriting

Q DP problem:
The TRS P consists of the following rules:

U11(X, right_out(ZS)) → FLAT_IN(ZS)
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))
FLAT_IN(tree(X, niltree, XS)) → U11(X, right_in(tree(X, niltree, XS)))

The TRS R consists of the following rules:

right_in(tree(X, XS1, XS2)) → right_out(XS2)

The set Q consists of the following terms:

right_in(x0)

We have to consider all (P,Q,R)-chains.
By rewriting [15] the rule FLAT_IN(tree(X, niltree, XS)) → U11(X, right_in(tree(X, niltree, XS))) at position [1] we obtained the following new rules:

FLAT_IN(tree(X, niltree, XS)) → U11(X, right_out(XS))



↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ Rewriting
QDP
                          ↳ UsableRulesProof

Q DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))
U11(X, right_out(ZS)) → FLAT_IN(ZS)
FLAT_IN(tree(X, niltree, XS)) → U11(X, right_out(XS))

The TRS R consists of the following rules:

right_in(tree(X, XS1, XS2)) → right_out(XS2)

The set Q consists of the following terms:

right_in(x0)

We have to consider all (P,Q,R)-chains.
As all Q-normal forms are R-normal forms we are in the innermost case. Hence, by the usable rules processor [15] we can delete all non-usable rules [17] from R.

↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ Rewriting
                        ↳ QDP
                          ↳ UsableRulesProof
QDP
                              ↳ QReductionProof

Q DP problem:
The TRS P consists of the following rules:

U11(X, right_out(ZS)) → FLAT_IN(ZS)
FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))
FLAT_IN(tree(X, niltree, XS)) → U11(X, right_out(XS))

R is empty.
The set Q consists of the following terms:

right_in(x0)

We have to consider all (P,Q,R)-chains.
We deleted the following terms from Q as each root-symbol of these terms does neither occur in P nor in R.

right_in(x0)



↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ Rewriting
                        ↳ QDP
                          ↳ UsableRulesProof
                            ↳ QDP
                              ↳ QReductionProof
QDP
                                  ↳ UsableRulesReductionPairsProof

Q DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))
U11(X, right_out(ZS)) → FLAT_IN(ZS)
FLAT_IN(tree(X, niltree, XS)) → U11(X, right_out(XS))

R is empty.
Q is empty.
We have to consider all (P,Q,R)-chains.
By using the usable rules with reduction pair processor [15] with a polynomial ordering [25], all dependency pairs and the corresponding usable rules [17] can be oriented non-strictly. All non-usable rules are removed, and those dependency pairs and usable rules that have been oriented strictly or contain non-usable symbols in their left-hand side are removed as well.

The following dependency pairs can be deleted:

U11(X, right_out(ZS)) → FLAT_IN(ZS)
FLAT_IN(tree(X, niltree, XS)) → U11(X, right_out(XS))
No rules are removed from R.

Used ordering: POLO with Polynomial interpretation [25]:

POL(FLAT_IN(x1)) = 1 + 2·x1   
POL(U11(x1, x2)) = 2 + 2·x1 + 2·x2   
POL(niltree) = 1   
POL(right_out(x1)) = x1   
POL(tree(x1, x2, x3)) = 2·x1 + x2 + x3   



↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ Rewriting
                        ↳ QDP
                          ↳ UsableRulesProof
                            ↳ QDP
                              ↳ QReductionProof
                                ↳ QDP
                                  ↳ UsableRulesReductionPairsProof
QDP
                                      ↳ RuleRemovalProof

Q DP problem:
The TRS P consists of the following rules:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))

R is empty.
Q is empty.
We have to consider all (P,Q,R)-chains.
By using the rule removal processor [15] with the following polynomial ordering [25], at least one Dependency Pair or term rewrite system rule of this QDP problem can be strictly oriented.
Strictly oriented dependency pairs:

FLAT_IN(tree(X, tree(Y, YS1, YS2), XS)) → FLAT_IN(tree(Y, YS1, tree(X, YS2, XS)))


Used ordering: POLO with Polynomial interpretation [25]:

POL(FLAT_IN(x1)) = 2·x1   
POL(tree(x1, x2, x3)) = 2 + 2·x1 + 2·x2 + x3   



↳ Prolog
  ↳ PrologToPiTRSProof
    ↳ PiTRS
      ↳ DependencyPairsProof
        ↳ PiDP
          ↳ DependencyGraphProof
            ↳ PiDP
              ↳ UsableRulesProof
                ↳ PiDP
                  ↳ PiDPToQDPProof
                    ↳ QDP
                      ↳ Rewriting
                        ↳ QDP
                          ↳ UsableRulesProof
                            ↳ QDP
                              ↳ QReductionProof
                                ↳ QDP
                                  ↳ UsableRulesReductionPairsProof
                                    ↳ QDP
                                      ↳ RuleRemovalProof
QDP
                                          ↳ PisEmptyProof

Q DP problem:
P is empty.
R is empty.
Q is empty.
We have to consider all (P,Q,R)-chains.
The TRS P is empty. Hence, there is no (P,Q,R) chain.